<template>
    <div class="box">
        <main>
            <h3 class="title">登录你的账户</h3>
            <a-form :model="formLogin" name="basic" autocomplete="off" @finish="onFinish" @finishFailed="onFinishFailed">
                <a-form-item name="userName" :rules="formLoginRules.userName">
                    <a-input class="form_input" v-model:value="formLogin.userName" placeholder="请输入账号">
                        <template #prefix>
                            <UserOutlined />
                        </template></a-input>
                </a-form-item>

                <a-form-item name="password" :rules="formLoginRules.password">
                    <a-input-password class="form_input" v-model:value="formLogin.password" placeholder="请输入密码">
                        <template #prefix>
                            <LockOutlined />
                        </template>
                    </a-input-password>
                </a-form-item>
                <a-form-item>
                    <a-button class="login-submit" type="primary" html-type="submit">登录</a-button>
                </a-form-item>
            </a-form>
        </main>
    </div>
</template>

<script lang="ts" setup>
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue';
import { reactive } from 'vue';
import { message } from 'ant-design-vue';
import login from '@/composables/request/login';
import type loginType from '@/composables/request/instanceof/loginType'
import { useRouter } from 'vue-router'

const router = useRouter();
const formLogin = reactive<loginType>({
    userName: 'xiaoke',
    password: '123456',
});

const formLoginRules = reactive({
    userName: [{ required: true, message: '请输入账号' }],
    password: [{ required: true, message: '请输入密码' }],
});
const onFinish = async (values: loginType) => {
    const isLogin = await login(values);
    if (isLogin) {
        await router.push("/admin/home")
    }
};

const onFinishFailed = (errorInfo: any) => {
    message.error('请完整填写表单');
};

</script>


<style lang="less" scoped>
.box {
    width: 100vw;
    height: 100vh;
    background-image: linear-gradient(to top right, #0a50b6, #105fc4, #03aad1, #03aad1, #41a4d4, #c05bd2);
}

main {
    position: absolute;
    width: 400px;
    height: 380px;
    background: white;
    right: 15%;
    top: 50%;
    transform: translate(0, -50%);
    border-radius: 10px;
    box-shadow: 0px 8px 15px rgba(29, 167, 210, .6);
    padding: 40px;

    .form_input {
        height: 40px;
    }

    .title {
        letter-spacing: 3px;
        font-size: 22px;
        font-weight: 500;
        margin-bottom: 40px;
        color: var(--el-text-color-primary);
    }

    .login-submit {
        margin-top: 30px;
        width: 100%;
        height: 40px;
    }
}
</style>